<template>
	<view class="task-wrap">
		<view class="clomn-wrap" style="position: relative;">
			<view class="imageD" style="margin: 10px;">
				<image style="width: 100%; height: 100%;border-radius: 10rpx;"
					:src=" 'https://www.huancelian.com/azImg/' + image "></image>
			</view>
			<view class="tabContainer" style="margin-bottom: 5px;">
				<!-- 仪器信息 -->
				<view class="project-info">
					<view class="sample-detail">
						<text class="title">仪器名称</text>
						<text class="value">{{datainfo.name ||""}}</text>
					</view>
					<!-- 分割线 -->
					<view class="divLine"></view>

					<view class="sample-detail">
						<text class="title">仪器编号</text>
						<text class="value">{{datainfo.number ||""}}</text>
					</view>
					<!-- 分割线 -->
					<view class="divLine"></view>

					<view class="sample-detail">
						<text class="title">仪器负责人</text>
						<text class="value">{{datainfo.blame || ""}}</text>
					</view>
					<!-- 分割线 -->
					<view class="divLine"></view>

					<view class="sample-detail">
						<text class="title">仪器权属</text>
						<text class="value" v-if="datainfo.isOwn == '1'">自有</text>
						<text class="value" v-if="datainfo.isOwn == '2'">外借</text>
					</view>
					<!-- 分割线 -->
					<view class="divLine"></view>

					<view class="sample-detail">
						<text class="title">仪器状态</text>
						<text class="value" v-if="datainfo.status == '0'">报废</text>
						<text class="value" v-if="datainfo.status == '1'">降级</text>
						<text class="value" v-if="datainfo.status == '2'">停用</text>
						<text class="value" v-if="datainfo.status == '3'">准用</text>
						<text class="value" v-if="datainfo.status == '4'">合格</text>
					</view>
					<!-- 分割线 -->
					<view class="divLine"></view>

					<view class="sample-detail">
						<text class="title">下次检定/校准日期</text>
						<text class="value">{{datainfo.nextTime ||""}}</text>
					</view>

					<view v-if="device">
						<!-- 分割线 -->
						<view class="divLine"></view>

						<view class="sample-detail">
							<text class="title">最近预约使用日期</text>
							<text class="value">{{datainfo.start ||""}}</text>
						</view>

						<!-- 分割线 -->
						<view class="divLine"></view>

						<view class="sample-detail">
							<text class="title">预计使用单号</text>
							<text class="value">{{datainfo.jobId ||""}}</text>
						</view>
					</view>
				</view>
			</view>
			<button class="button_login" v-if="disapp" @click="goDetail">登录</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				datainfo: {},
				imageHTTPS: "https://www.huancelian.com/azImg/",
				image: "",
				id: "",
				device: false,
				scanTheCode: "",
				type:"",
				disappear:'',
				disapp: true,
				arr: [
					"TeA",
					"sbcj",
					"KS",
					"Po",
				],
				arr1: [
					"sbcj",
					"TeA",
				],
				arr2: [
					"KS",
					"Po",
				]
			}
		},
		methods: {
			onLoad(option) {
				// 在onLoad事件中提取q参数并自行decodeURIComponent一次
				// 即可获取原二维码的完整内容
				const qrCodeContent = decodeURIComponent(option.q)
				console.log("二维码的内容:", qrCodeContent)
				const meetingID = qrCodeContent.split('id=')[1]
				console.log("从二维码中解析的会议id为：", meetingID)
				this.id = meetingID
				if(option.id != undefined){
					this.id = option.id
				}
				this.disappear = option.disappear
				console.log(this.disappear)
				if(this.disappear == 1){
					console.log(5555)
					this.disapp = false
				}
				this.detail()
				this.sceneDevice()
			},
			detail() {
				this.$api.detail({
					id: this.id
				}, res => {
					console.log(res)
					if (res.result.type == 3) {
						this.device = true
						this.scanTheCode = 1
						this.type = 3
						// this.disapp = true
						if (res.code === 200) {
							console.log("实验室仪器")
							this.datainfo = res.result || {}
							this.image = this.datainfo.image1
							console.log(this.image)
						}
					} else if (res.result.type == 4) {
						this.device = true
						this.scanTheCode = 1
						this.type = 4
						// this.disapp = true
						if (res.code === 200) {
							console.log("校准仪器")
							this.datainfo = res.result || {}
							this.image = this.datainfo.image1
							console.log(this.image)
						}
					} else if (res.result.type == 5) {
						this.device = true
						this.scanTheCode = 1
						this.type = 5
						// this.disapp = true
						if (res.code === 200) {
							console.log("样品制备仪器")
							this.datainfo = res.result || {}
							this.image = this.datainfo.image1
							console.log(this.image)
						}
					}
				})
			},
			sceneDevice() {
				this.$api.sceneDevice({
					id: this.id
				}, res => {
					console.log(res)
					if (res.result.type == 1) {
						this.device = true
						this.scanTheCode = 1
						this.type = 1
						// this.disapp = true
						if (res.code === 200) {
							console.log("现场采样仪器")
							this.datainfo = res.result || {}
							this.image = this.datainfo.image1
							console.log(this.image)
						}
					} else if (res.result.type == 2) {
						this.device = true
						this.scanTheCode = 1
						this.type = 2
						// this.disapp = true
						if (res.code === 200) {
							console.log("现场检测仪器 ")
							this.datainfo = res.result || {}
							this.image = this.datainfo.image1
							console.log(this.image)
						}
					}
				})
			},
			goDetail() {
				const value = wx.getStorageSync('userToken')
				console.log('userToken',value)
				if(value != null){
					this.getUserInfo()
				}else{
					console.log(444)
					wx.navigateTo({
						url: '/pages/login/index?id=' + this.id + "&scanTheCode=" + this.scanTheCode + "&type=" + this.type
					})
				}
				
			},
			getUserInfo() {
				this.$api.getUserInfo(res => {
					if (res.success && res.result) {
						console.log(res.result)
						this.name = res.result.empName
						this.roles = res.result.roles
						this.$store.commit('SAVE_CUR_USER', res.result);
						if (res.result.roles.length > 0) {
							this.$store.commit('SAVE_ROLE_LISTS', res.result.roles);
			
							// 交集
							this.intersection = this.arr.filter(function(val) {
									return res.result.roles.indexOf(val) > -1
								}),
			
								// // 交集
								this.inCode = this.arr1.filter(function(val) {
									return res.result.roles.indexOf(val) > -1
								}),
			
								// 交集
								this.inScanThe = this.arr2.filter(function(val) {
									return res.result.roles.indexOf(val) > -1
								}),
			
			
								console.log('交集', this.intersection);
							switch (this.intersection[0]) {
								case 'KS':
									this.$store.commit('SAVE_CUR_ROLE', {
										roleId: "KS",
										roleName: '采样员'
									});
									break
								case 'Po':
									this.$store.commit('SAVE_CUR_ROLE', {
										roleId: "Po",
										roleName: '采样组长'
									});
									break
								case 'sbcj':
									this.$store.commit('SAVE_CUR_ROLE', {
										roleId: "sbcj",
										roleName: '仪器设备管理员'
									});
									break
								case 'TeA':
									this.$store.commit('SAVE_CUR_ROLE', {
										roleId: "TeA",
										roleName: '分析员'
									});
									break
								default:
									this.$store.commit('SAVE_CUR_ROLE', {});
							}
						} else {
							this.$store.commit('SAVE_ROLE_LISTS', res.result.roles);
			
						}
			
						if (this.intersection[0] == 'TeA') {
							wx.navigateTo({
								url: '/pages/maintenance/index?id=' + this.id + "&empName=" + this
									.name + "&scanTheCode=" + this.scanTheCode
							})
						}
						if (this.intersection[0] == 'sbcj') {
							console.log("成功")
							wx.reLaunch({
								url: '/pages/instrument/index?id=' + this.id +
									"&empName=" + this
									.name + "&scanTheCode=" + this.scanTheCode + '&sbcj=' + "sbcj"
							})
						}
						if (this.intersection[0] == 'KS' || this.intersection[0] == 'Po') {
							uni.reLaunch({
								url: '/pages/mine/index?id=' + this.id +
									"&empName=" + this
									.name + "&scanTheCode=" + this.scanTheCode
							});
						}
			
			
			
						if (this.type == 3 || this.type == 4 || this.type == 5) {
							if (this.scanTheCode != "") {
								if (this.inCode[0] == 'sbcj') {
									wx.reLaunch({
										url: '/pages/warehouse/index?id=' + this.id +
											"&empName=" + this
											.name + '&sbcj=' + "sbcj"
									})
								}
							} else {
								if (this.inCode[0] == 'sbcj') {
									wx.reLaunch({
										url: '/pages/InstrumentManagement/index?id=' + this.id +
											"&empName=" + this
											.name + '&sbcj=' + "sbcj"
									})
								}
							}
						}
			
			
						if (this.type == 1 || this.type == 2) {
							if (this.scanTheCode != "") {
								if (this.inScanThe[0] == 'KS' || this.inScanThe[0] == 'Po') {
									uni.reLaunch({
										url: '/pages/claim/index?id=' + this.id +
											"&empName=" + this
											.name
									});
								}
							} else {
								if (this.inScanThe[0] == 'KS' || this.inScanThe[0] == 'Po') {
									uni.reLaunch({
										url: '/pages/mine/index?id=' + this.id +
											"&empName=" + this
											.name
									});
								}
							}
						}
					} else {
						this.$common.errorToShow(res.result)
					}
				})
			},
		}
	}
</script>

<style scoped>
	.imageD {
		width: 712rpx;
		height: 712rpx;
		display: inline-block;
		box-sizing: border-box;
		left: 0rpx;
		top: 0rpx;
		position: relative
	}

	.tabContainer {
		overflow-x: hidden;
		width: 100%;
		/* height: 100%; */
		padding-bottom: 30rpx;
		padding-left: 27rpx;
		padding-right: 27rpx;
	}

	.project-info {
		/* height: 280rpx; */
		width: calc(100%-98rpx);
		background-color: #ffffff;
		margin-top: 5rpx;
		padding-top: 5rpx;
		padding-right: 49rpx;
		padding-bottom: 20rpx;
		border-radius: 19rpx;
	}

	.sample-detail {
		margin-top: 20rpx;
		font-size: 25rpx;
		height: 40rpx;
		display: flex;
		align-items: center;

	}

	.sample-detail .title {
		color: #2E2E2E;
		font-weight: bolder;
		opacity: 0.8;
		display: inline-block;
		width: 250rpx;
		padding-left: 30rpx;
	}

	.sample-detail .value {
		color: #555555;
		font-weight: 400;
		opacity: 0.7;
		width: 65%;
		display: inline-block;
		padding-left: 150rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		display: inline-block;
	}

	/*分割线样式*/
	.divLine {
		background: #eff1e9;
		width: 100%;
		height: 1rpx;
		margin: 20rpx;
	}

	.button_login {
		margin-top: 10rpx;
		display: block;
		width: 170rpx;
		height: 60rpx;
		padding-left: 30rpx;
		padding-top: 0rpx;
		font-size: 25rpx;
		background-color: #193566;
		color: #fff;
		letter-spacing: 1rpx;
	}

	.task-wrap {
		/* display: block; */
		width: 100%;
		height: 125%;
	}
</style>